﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Data.SqlClient;
using KVB.Common;
namespace Customer_Profile.ClientManage
{
    public partial class CheckExist : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Request.ServerVariables["REQUEST_METHOD"] == "POST")
            {                
                if (Request["ID"] != null && Request["ID"].ToString() != "")
                {
                    if (Request["guid"]==null||Request["guid"] == "")
                    {
                        try
                        {
                            DataSet ds = new DataSet();
                            SqlParameter[] parameters ={ new SqlParameter("@ID", SqlDbType.NVarChar, 50) };
                            parameters[0].Value = Request["ID"].ToString();
                            SqlConnection conn = null;
                            DB.Connection(ref conn);
                            ds = DB.ExecuteDataset(conn, CommandType.StoredProcedure, "Proc_CheckExistByIbID", parameters);
                            if (ds.Tables.Count > 0)
                            {
                                if (int.Parse(ds.Tables[0].Rows[0][0].ToString()) > 0)
                                {
                                    Response.Write("<img alt='' src='../images/reg_msg_error.gif' border='0'/>");
                                }
                                else
                                {
                                    Response.Write("<img alt='' src='../images/reg_msg_ok.gif' border='0'/>");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteDefaultLog("CheckExistPage_Load", ex.ToString());
                        }
                    }
                    else
                    {
                        try
                        {
                            DataSet ds = new DataSet();
                            SqlParameter[] parameters ={ new SqlParameter("@ID", SqlDbType.NVarChar, 50),
                                                         new SqlParameter("@Guid",SqlDbType.VarChar,50)};
                            parameters[0].Value = Request["ID"].ToString();
                            parameters[1].Value = Request["guid"].ToString();
                            SqlConnection conn = null;
                            DB.Connection(ref conn);
                            ds = DB.ExecuteDataset(conn, CommandType.StoredProcedure, "Proc_CheckExistEditByIbID", parameters);
                            if (ds.Tables.Count > 0)
                            {
                                if (int.Parse(ds.Tables[0].Rows[0][0].ToString()) > 0)
                                {
                                    Response.Write("<img alt='' src='../images/reg_msg_error.gif' border='0'/>");
                                }
                                else
                                {
                                    Response.Write("<img alt='' src='../images/reg_msg_ok.gif' border='0'/>");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log.WriteDefaultLog("CheckExistPage_LoadEdit", ex.ToString());
                        }
                    }
                }
                else
                {
                    Response.Write("<span style=\"color:#880000\">ID Must Fill</span>");
                }
            }
        }
    }
}
